{% import '_globalhelpers.html' as globals %}

{% macro paginate(pg, url, page, params={}) %}
    {% if pg.has_prev %}
    <li><a href="{{ url_for(url, page=pg.prev_num, **params) }}">«</a></li>
    {% endif %}

    {%- for page in pg.iter_pages() %}
        {% if page %}
            {% if page != pg.page %}
            <li><a href="{{ url_for(url, page=page, **params) }}">{{ page }}</a></li>
            {% else %}
            <li class="active"><a href="#">Page {{ pg.page }} of {{ pg.pages }}</a></li>
            {% endif %}
        {% else %}
        <li><span class=ellipsis>…</span></li>
        {% endif %}
    {%- endfor %}
    {% if pg.has_next %}
        <li><a href="{{ url_for(url, page=pg.next_num, **params) }}">»</a></li>
    {% endif %}
{% endmacro %}

{% macro score_pill(score) %}
  <a href="{{ url_for('.grading', bid=score.backup_id) }}">
    {% if score.kind in score.assignment.published_scores %}
      <span class="label label-success score-inline" title="Visible to students">{{ score.kind.title() }}: {{ score.score | round(2) }}
        <i class="fa fa-eye" aria-hidden="true"></i>
      </span>
    {% else %}
      <span class="label label-default score-inline" title="Hidden to students">{{ score.kind.title() }}: {{ score.score | round(2) }}
        <i class="fa fa-eye-slash" aria-hidden="true"></i>
      </span>
    {% endif %}
  </a>
{% endmacro %}

{% macro score_pills(scores) %}
  {% for score in scores %}
    {{ score_pill(score) }}
  {% else %}
    &mdash;
  {% endfor %}
{% endmacro %}

{% macro tag_pill(tag) %}
  <a href="?tag={{tag}}">
      <span class="label label-info score-inline">{{ tag }} </span>
  </a>
{% endmacro %}

{% macro tag_pills(tags) %}
  {% for tag in tags %}
    {{ tag_pill(tag) }}
  {% else %}
    &mdash;
  {% endfor %}
{% endmacro %}

{% macro backup_link(backup_id) %}
    <a href="{{ url_for('.grading', bid=backup_id) }}">
        {{ globals.backup_style(utils.encode_id(backup_id)) }}
        {% if caller %} {{ caller() }} {% endif %}
    </a>
{% endmacro %}
